// lazy 懒
import { lazy, Suspense } from 'react'
import { Router, Route, Redirect } from 'react-router-dom'

import { history } from './utils/history'

import './App.css'

// 在 App 组件中配置路由
import { AuthRoute } from './components/AuthRoute'

// 导入页面组件
const Login = lazy(() => import('./pages/Login'))
const Layout = lazy(() => import('./pages/Layout'))

const App = () => {
  return (
    // 自定义 history
    <Router history={history}>
      <Suspense
        fallback={
          <div
            style={{
              textAlign: 'center',
              marginTop: 200
            }}
          >
            loading...
          </div>
        }
      >
        <div className="app">
          <Route exact path="/" render={() => <Redirect to="/home" />}></Route>
          <Route path="/login">
            <Login />
          </Route>
          <AuthRoute path="/home">
            <Layout />
          </AuthRoute>
        </div>
      </Suspense>
    </Router>
  )
}

export default App
